<% if notice %>  
<p id="notice"><%= notice %></p>  
<% end %>  
<h1>Your Pragmatic Catalog</h1>  
<% @products.each do |product| %>  
    <div class="entry">  
    <%= image_tag product.picture.url if product.picture? %>
    <%#    <%=image_tag(product.image_url)  %>  
        <h3><%= product.title %></h3>  

        <%= sanitize(product.description) %>  
        <div class="price_line">  
            <span class="price"><%=number_to_currency(product.price ) %></span>  
            <%= button_to '添加到购物车', line_items_path(product_id: product) %>
        </div>  
    </div>  


 <div class="comment">  

      <% if !log_in? %>
    <h2>新增评论:</h2>
<%= form_for([product, product.comments.build]) do |f| %>
 <%= f.hidden_field :commenter, :value => current_user_name %>
  <p>
    内容:
    <%= f.text_area :body %>
  </p>
  <p>
    <%= f.submit %>
  </p>
          <% end %>
      <% end %>
</div>
 <div class="comment">  
                <% if has_any_comment? (product)%>
<h2>评论</h2>
<% product.comments.each do |comment| %>
                                <% if  !comment.body.nil?%>
      <p>
      <strong>评论人:</strong>
    <%= comment.commenter %>
    </p>

   <p>
    <strong>评论内容</strong>
    <%= comment.body %>
    </p>



                                               <% if !log_in? %>
                                                                 <% if  is_admin? %>
<%= link_to "delete", comment, method: :delete,data: { confirm: "You sure?" } %>
                                                                  <% end %>
                                                <% end %>

                                <% end %>
                      <h3></h3>
                 <% end %>
</div>
          <% end %>

<% end %>  